package com.ruoyi.carwash.controller;

import com.ruoyi.carwash.domain.Order;
import com.ruoyi.carwash.service.OrderService;
import com.ruoyi.carwash.vo.OrderVo;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orders")
public class OrderController extends BaseController {

    @Autowired
    private OrderService orderService;

    /**
     * 分页查询订单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(OrderVo order){
        startPage();
        List<OrderVo> orders = orderService.selectOrderList(order);
        return getDataTable(orders);
    }

    /**
     * 获取订单详情
     */
    @GetMapping("/{id}")
    public ResponseEntity<Order> getOrderDetail(@PathVariable Long id) {
        return ResponseEntity.ok(orderService.getOrderDetail(id));
    }

    /**
     * 更新订单状态
     */
    @PutMapping("/{id}/status")
    public ResponseEntity<Void> updateOrderStatus(
            @PathVariable Long id,
            @RequestParam Integer status) {
        orderService.updateOrderStatus(id, status);
        return ResponseEntity.ok().build();
    }

    /**
     * 更新支付状态
     */
    @PutMapping("/{id}/payment")
    public ResponseEntity<Void> updatePaymentStatus(
            @PathVariable Long id,
            @RequestParam Integer paymentStatus,
            @RequestParam(required = false) String paymentTransactionId) {
        orderService.updatePaymentStatus(id, paymentStatus, paymentTransactionId);
        return ResponseEntity.ok().build();
    }
}